﻿using DevExpress.XtraBars;
using DevExpress.XtraTreeList.Nodes;
using Event;
using FromUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RequestDirectory
{
    /// <summary>
    /// 节点打开
    /// </summary>
    static class NodeOpen
    {
        /// <summary>
        /// 双击点击Node的动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="currentNode"></param>
        public static void NodeDoubleOpen(object sender, MouseEventArgs e, ref TreeListNode currentNode)
        {
            TreeListNode tn = TreeListTool.GetFocusNode(sender, e.Location);
            if (e.Button == System.Windows.Forms.MouseButtons.Left && tn != null)
            {
                currentNode = tn;
                string stringtype = (string)currentNode.GetValue("type");
                //文件类型 就打开请求界面
                if (stringtype.Equals("file"))
                {
                    string id = currentNode.GetValue("ID").ToString();
                    string key = currentNode.GetValue("key").ToString();

                    //设置打开次数
                    int opendnumber = (int)currentNode.GetValue("opendnumber");
                    currentNode.SetValue("opendnumber", opendnumber + 1);

                    EventGlobal.SetIndexTabbedViewOpenNew(id, key, currentNode);
                }
                //文件夹类型 双击收缩或展开
                if (stringtype.Equals("filegroup"))
                {
                    //true 是由未展开,false 已经展开
                   if(currentNode.Expanded == true ){
                       currentNode.Expand();                       
                   }else{
                       currentNode.Collapse();
                   } 
                }
            }
        }
        
        /// <summary>
        /// 单点击Node的动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="currentNode"></param>
        public static void NodeDoubleOpen(object sender, ItemClickEventArgs e, ref TreeListNode currentNode)
        {
            string stringtype = (string)currentNode.GetValue("type");
            if (stringtype.Equals("file"))
            {
                string id = currentNode.GetValue("ID").ToString();
                string key = currentNode.GetValue("key").ToString();

                //设置打开次数
                int opendnumber = (int)currentNode.GetValue("opendnumber");
                currentNode.SetValue("opendnumber", opendnumber + 1);

                EventGlobal.SetIndexTabbedViewOpenNew(id, key, currentNode);
            }
            //文件夹类型 双击收缩或展开
            if (stringtype.Equals("filegroup"))
            {
                //true 是展开,false未展开
                if (currentNode.Expanded == true)
                {
                    currentNode.Collapse();
                }
                else
                {
                    currentNode.ExpandAll();
                }
            }
        }
    }

}
